package com.weetop.aklyscan.presenter;

import android.app.Activity;

import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.base.mvp.BaseObserver;
import com.weetop.aklyscan.base.mvp.BasePresenter;
import com.weetop.aklyscan.bean.ChaXunBean;
import com.weetop.aklyscan.bean.FittingDetailBean;
import com.weetop.aklyscan.bean.FittingInfo;
import com.weetop.aklyscan.bean.InStockItemBean;
import com.weetop.aklyscan.bean.ProductDetailBean;
import com.weetop.aklyscan.bean.ProductInfo;
import com.weetop.aklyscan.bean.RecordListBean;
import com.weetop.aklyscan.bean.ScanShelfCodeBean;
import com.weetop.aklyscan.bean.TypeInfo;
import com.weetop.aklyscan.bean.ZXGoodsInfo;
import com.weetop.aklyscan.bean.ZXOrderInfo;
import com.weetop.aklyscan.view.WxInStockView;

import org.json.JSONArray;

import java.util.List;

public class WxInStockPresent extends BasePresenter<WxInStockView> {

    public WxInStockPresent(WxInStockView baseView, Activity activity) {
        super(baseView, activity);
    }

    /**
     * @param type_id  产品类型：1产品；2配件
     * @param order_sn 入库单编号
     */
    public void inStockDetail01(String type_id, String order_sn) {
        addDisposable(apiServer.intoDetail01(type_id, order_sn), new BaseObserver<BaseModel<List<ProductDetailBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ProductDetailBean>> o) {
                baseView.getInStockDetail01Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * @param type_id  产品类型：1产品；2配件
     * @param order_sn 入库单编号
     */
    public void inStockDetail02(String type_id, String order_sn) {
        addDisposable(apiServer.intoDetail02(type_id, order_sn), new BaseObserver<BaseModel<List<FittingDetailBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<FittingDetailBean>> o) {
                baseView.getInStockDetail02Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void scanShelfCode(String code) {
        addDisposable(apiServer.scanShelfCode(code), new BaseObserver<BaseModel<ScanShelfCodeBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ScanShelfCodeBean> o) {
                baseView.scanShelfCodeSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    //items : List<IntoSaveBean>
    public void intoKuSave(String type_id, String order_sn, String tier_id, String items) {
//        String itemsString = GsonUtils.toJson(items);
        addDisposable(apiServer.intoKuSave(type_id, order_sn, tier_id, items), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.saveIntoKuSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void Into07(String matter_code) {
        addDisposable(apiServer.Into07(matter_code), new BaseObserver<BaseModel<FittingInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<FittingInfo> o) {
                baseView.getInto07Success(matter_code, o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    public void scanProduct(String goods_sn) {
        addDisposable(apiServer.getProductInfo(goods_sn), new BaseObserver<BaseModel<ProductInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ProductInfo> o) {
                baseView.getProductInfSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into08(String type, String serial_code, String order_sn) {
        addDisposable(apiServer.Into08(type, serial_code,order_sn), new BaseObserver<BaseModel<ZXGoodsInfo>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ZXGoodsInfo> o) {
                baseView.getInto08Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onError();
                }
            }
        });
    }

    public void Into10() {
        addDisposable(apiServer.Into10(), new BaseObserver<BaseModel<List<TypeInfo>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<TypeInfo>> o) {
                baseView.getInto10Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into11() {
        addDisposable(apiServer.Into11(), new BaseObserver<BaseModel<List<TypeInfo>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<TypeInfo>> o) {
                baseView.getInto11Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void saveZx(String barcode) {
        addDisposable(apiServer.into01(barcode), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.saveZxSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void Into12(String shop_type, String order_type, String port_type, String order_sn,final int b) {
        addDisposable(apiServer.Into12(shop_type, order_type, port_type, order_sn), new BaseObserver<BaseModel<List<ZXOrderInfo>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ZXOrderInfo>> o) {
                baseView.getInto12Success(o,b);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void Into13(String code) {
        addDisposable(apiServer.Into13(code), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.getInto13Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void Into14(String barcode) {
        addDisposable(apiServer.Into14(barcode), new BaseObserver<BaseModel<List<ZXGoodsInfo>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ZXGoodsInfo>> o) {
                baseView.getInto14Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void Into15(String shop_type, String order_sn, String tier_code, JSONArray items, String order_type) {
        addDisposable(apiServer.Into15(shop_type, order_sn, tier_code, items, order_type), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getInto15Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onUpFail(msg);
                }
            }
        });
    }

    public void Into16(String order_sn, JSONArray items) {
        addDisposable(apiServer.Into16(order_sn, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getInto16Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onUpFail(msg);
                }
            }
        });
    }
    public void Into17(String order_sn, JSONArray items) {
        addDisposable(apiServer.Into17(order_sn, items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getInto17Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onUpFail(msg);
                }
            }
        });
    }

    public void Into24(String order_sn, JSONArray items) {
        addDisposable(apiServer.Into24(order_sn, items), new BaseObserver<BaseModel<List<ChaXunBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<List<ChaXunBean>> o) {
                baseView.getInto24Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }
    public void Into25(String order_type,String order_sn) {
        addDisposable(apiServer.Into25(order_type,order_sn), new BaseObserver<BaseModel<Object>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Object> o) {
                baseView.getInto25Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.onDataError();
                }
            }
        });
    }

    public void Into46(String serial_code) {
        addDisposable(apiServer.Into46(serial_code), new BaseObserver<BaseModel<InStockItemBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<InStockItemBean> o) {
                baseView.getInto46Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    public void Into47(String tier_code,JSONArray items) {
        addDisposable(apiServer.Into47(tier_code,items), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.getInto47Success(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }
}
